//
//  RootViewController.h
//  weibo3
//
//  Created by Tian Wu on 11-4-8.
//  Copyright 2011年 nfsysu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Constants.h"
#import "HttpClient.h"
#import "Status.h"
#import "InvalidParameterException.h"
#import "ServerSideException.h"
#import "statusCell.h"
#import "newTweet.h"
#import "ViewImage.h"
#import "TabTable.h"
#import "WComment.h"
#import "UnreadCount.h"
#import "PreferenceController.h"
#import "TimelineCacheManager.h"
#import "OauthSingnature.h"

static const double nilLatitude = 200;
static const double nilLongitude = 200;
static const weiboId nilReplyId = 0;

@class LoginWindow;
@class newTweet;
@class ViewImage;
@class PreferenceController;
@class TabTable;

@interface RootViewController : NSWindowController
<NSTableViewDataSource ,NSTableViewDelegate, NSApplicationDelegate, NSWindowDelegate>{
    @private HttpClient * client;
    
    TimelineCacheManager *cacheManager;
    
    NSDockTile * dockTile;
    
    IBOutlet NSTextField *textField;
    
    NSArray *publicData;
    NSArray *thumbData;
    IBOutlet NSImageView *myProfileImage;
    PXListView *listView;
    
    IBOutlet NSProgressIndicator *progress;
    IBOutlet NSTextField *myFans;

    NSString *imgURL;
    User *currentUser;
    
    BOOL before;
    
    IBOutlet NSTableView *tabTable;
    IBOutlet NSTableView *blueDotTable;
    IBOutlet TabTable *_tabTable;
    IBOutlet NSTextField *page;
    
    PreferenceController *preferenceWindow;
    
    LoginWindow *myEditController;
    
    OAToken                 *accessToken;
    
    newTweet *newTweetWindow;
    ViewImage *viewimage;
    
    NSDate * lastAppendStatusTime;
        
    IBOutlet NSWindow *theWindow;
}

@property (readwrite,retain) NSArray *publicData;
@property (readwrite,retain) NSArray *thumbData;
@property (readwrite,retain) NSString *imgURL;
@property (readwrite,retain) User *currentUser;
@property (readwrite,retain) IBOutlet PXListView *listView;
@property (assign) TimelineCacheManager *cacheManager;

- (IBAction) sendWeibo: (id) sender;
- (IBAction) selectImg: (id) sender;
- (IBAction) didLogin: (id) sender;

- (IBAction) newWeibo: (id) sender;
- (IBAction) showPreference:(id)sender;


//status and comment
- (NSArray *)getPublicTimeline:(int) count; // statuses/public_timeline
- (NSArray *)getFriendsTimeline:(weiboId) sinceId maxId:(weiboId) maxid count:(int ) maxCount page:(int) currentPage;
- (NSArray *)getUserTimeline:(weiboId) uid userId:(int ) userId screenName:(NSString *) screenName 
                     sinceId:(weiboId) sinceId maxId:(weiboId) maxid count:(int ) maxCount page:(int) currentPage;
- (NSArray *)getCommentsTimeline:(weiboId) sinceId maxId:(weiboId) maxid count:(int) maxCount page:(int) currentPage;
- (NSArray *)getComments:(weiboId) statusId count:(int) maxCount page:(int) currentPage;
- (UnreadCount *)getUnreadCountSinceId:(weiboId) since_id includeNewStatus:(int) with_new_status;
- (NSArray *)getEmotionsArrayWithCount:(int) count;

- (void) comment:(weiboId) statusId commentString:(NSString *) commentString;
- (WComment *)statusReply:(weiboId ) statusId commentId:(weiboId ) commentId comment:(NSString *) comment;

- (Status *)statusDestroy:(weiboId) statusId;
- (User *)verifyUser;

- (Status *)statusRepost:(weiboId) statusId status:(NSString *) status isComment:(int) withComment;

- (void) refreshStatus: (NSInteger) function;

- (void) refreshStatusWithFunction: (NSInteger) function Page:(NSInteger) page;

- (void) refreshFriendsStatusWithUserid:(int) userId Page:(int)pages;

- (void) loadNextPageStatus;

- (void) loginInit;

- (BOOL) didBackgroundCheck;

//+ (void) initFace;

- (Status *)statusUpdate:(NSString *) status inReplyToStatusId:(weiboId) replyToId latitude:(double) lat longitude:(double) longitude;

- (Status *)statusUpload:(NSString *) status pic:(NSString *) pic latitude:(double ) latitude longitude:(double) longitude;

- (Status *)statusAtIndexRow:(NSInteger) row;

- (void) viewImageInRow:(NSInteger) row;
- (void) replyCommentInRow:(NSInteger) row;
- (void)resetCountWithType:(int) type;

- (void)scrollToTop:(id)sender;

- (void) selectTabByIndex:(int) index;

- (BOOL)requestRequestToken;
- (void) askUserForAuthorization;
- (void)requestAccessToken;

@end
